// ComScrollBar.cpp : 实现文件
//

#include "stdafx.h"
#include "ComScrollBar.h"

#ifdef _DEBUG
#define new new( _NORMAL_BLOCK, __FILE__, __LINE__)  
#endif

/*#define     SIZE_SCROLL			16*/
#define     MIN_THUMB_LENGTH    45
#define     TIMER_ALLOW         0    

Image*      CComScrollBar::m_pImgBk = NULL;
Image*	    CComScrollBar::m_pThunk = NULL;
SScrollImg  CComScrollBar::m_thumbTop;
SScrollImg  CComScrollBar::m_thumbCenter;
SScrollImg  CComScrollBar::m_thumbBottom;
SScrollImg  CComScrollBar::m_allowUp;
SScrollImg  CComScrollBar::m_allowDown;
SScrollImg  CComScrollBar::m_allowLeft;
SScrollImg  CComScrollBar::m_allowRight;
// CComScrollBar

IMPLEMENT_DYNAMIC(CComScrollBar, CWnd)

CComScrollBar::CComScrollBar()
{
	m_pParent = NULL;
	m_pScrollCtrl = NULL;

	m_nBarType = SB_VERT;
	m_sizeScrollBar.cx = CUIConfig::PagePrint_GetPrintTaskWndScrollSize();

	m_nScrollPos = 0;	
	m_nAllSize = 0;	
	m_nPageSize = 0;	
	m_nOffsetSize = 0;

	m_bClickBar = FALSE;
	m_bHoverBar = FALSE;
	m_bHoverTrunk = FALSE;
	m_bClickTrunk = FALSE;

	m_bClickAllowUp = FALSE;
	m_bClickAllowDown = FALSE;
	m_bHoverAllowUp = FALSE;
	m_bHoverAllowDown = FALSE;
    m_clrSrcollBk =RGB(135,206,235) ;//;CColorConfig::PagePrint_GetPrintSrcollColorBk();
    m_clrTBBorder = RGB(135,206,235) ;//CColorConfig::PageFile_GetFileTreeScrollTBBorderColor();
}
CComScrollBar::~CComScrollBar()
{
}

BEGIN_MESSAGE_MAP(CComScrollBar, CWnd)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
    ON_WM_TIMER()
	ON_WM_SIZE()
	ON_WM_MOUSEWHEEL()
	ON_WM_MOUSEMOVE()
	ON_WM_MOUSEHOVER()
	ON_WM_MOUSELEAVE()
	ON_WM_LBUTTONUP()
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

// CComScrollBar 消息处理程序

void CComScrollBar::OnPaint()
{
	CPaintDC dc(this); 
	_Draw(&dc);
}
void CComScrollBar::OnTimer( UINT_PTR nIDEvent )
{
    if (TIMER_ALLOW == nIDEvent)
    {
        if (m_bClickAllowUp){
           SetScrollPos(m_nScrollPos - 10);
        }
        else if (m_bClickAllowDown){
           SetScrollPos(m_nScrollPos + 10);
        }
    }
    CWnd::OnTimer(nIDEvent);
}
void CComScrollBar::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);
}
BOOL CComScrollBar::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	UINT nPos = 0;

	nPos = GetScrollPos();
	if (zDelta < 0){
		nPos += m_nOffsetSize;
	}
	else if (zDelta > 0){
		nPos -= m_nOffsetSize;
	}
	SetScrollPos(nPos);
	return CWnd::OnMouseWheel(nFlags, zDelta, pt);
}
void CComScrollBar::OnMouseMove(UINT nFlags, CPoint point)
{
	if (m_bClickBar)
	{
		int	 nOffset = 0;
		int  nPos = 0;

		nOffset = point.y - m_ptLButtonDown.y;
		nOffset = (int)(nOffset / (double)m_nPageSize * m_nAllSize);
		nPos = GetScrollPos() + nOffset;
		SetScrollPos(nPos);
		m_ptLButtonDown = point;
	}
	else if (!m_bHoverBar && m_rcThumb.PtInRect(point)){
		m_bHoverBar = TRUE;
		InvalidateRect(m_rcThumb);
	}
	else if (m_bHoverBar && !m_rcThumb.PtInRect(point)){
		m_bHoverBar = FALSE;
		InvalidateRect(m_rcThumb);
	}
	else if(!m_bHoverAllowUp && m_rcAllowUp.PtInRect(point)){
		m_bHoverAllowUp = TRUE;
		InvalidateRect(m_rcAllowUp);
	}
	else if(m_bHoverAllowUp && !m_rcAllowUp.PtInRect(point)){
		m_bHoverAllowUp = FALSE;
		InvalidateRect(m_rcAllowUp);
	}
	else if(!m_bHoverAllowDown && m_rcAllowDown.PtInRect(point)){
		m_bHoverAllowDown = TRUE;
		InvalidateRect(m_rcAllowDown);
	}
	else if(m_bHoverAllowDown && !m_rcAllowDown.PtInRect(point)){
		m_bHoverAllowDown = FALSE;
		InvalidateRect(m_rcAllowDown);
	}

	if( m_bHoverTrunk == FALSE )
	{
		TRACKMOUSEEVENT tme;
		ZeroMemory(&tme,sizeof(TRACKMOUSEEVENT));
		tme.cbSize = sizeof(tme);
		tme.hwndTrack = m_hWnd;
		tme.dwFlags = TME_LEAVE|TME_HOVER;
		tme.dwHoverTime = 1;
		m_bHoverTrunk = _TrackMouseEvent(&tme);
	}
}
void CComScrollBar::OnMouseHover( UINT nFlags, CPoint point )
{
	if (!m_bHoverBar && m_rcThumb.PtInRect(point)){
		m_bHoverBar  =  TRUE;
		Invalidate();
	}
	
	CWnd::OnMouseHover(nFlags, point);
}
void CComScrollBar::OnMouseLeave()
{
	if (m_bHoverBar)
	{
		m_bHoverBar = FALSE;
		Invalidate();
	}
	m_bHoverTrunk = FALSE;
	CWnd::OnMouseLeave();
}
void CComScrollBar::OnLButtonDown(UINT nFlags, CPoint point)
{	
	SetFocus();
	if (m_bHoverBar && m_rcThumb.PtInRect(point))
	{
		m_bClickBar = TRUE;
		m_ptLButtonDown = point;
		SetCapture();
		Invalidate();
	}
	else if (m_bHoverAllowUp && m_rcAllowUp.PtInRect(point))
	{
		//m_bClickAllowUp = TRUE;
        m_bClickAllowUp = FALSE;
        SetTimer(TIMER_ALLOW, 100, NULL);
		InvalidateRect(m_rcAllowUp);
	}
	else if (m_bHoverAllowDown && m_rcAllowDown.PtInRect(point))
	{
		//m_bClickAllowDown = TRUE;
        m_bClickAllowDown = FALSE;
        SetTimer(TIMER_ALLOW, 100, NULL);
		InvalidateRect(m_rcAllowDown);
	}
	else if (m_bHoverTrunk && !m_rcThumb.PtInRect(point))
	{
		m_bClickTrunk = TRUE;
		if (m_nBarType == SB_VERT){
			if (m_rcThumb.bottom < point.y){
				SetScrollPos(m_nScrollPos + m_nPageSize);	
			}
			else if (m_rcThumb.top > point.y){
				SetScrollPos(m_nScrollPos - m_nPageSize);
			}
		}
		else if (m_nBarType == SB_HORZ){
			if (m_rcThumb.right < point.x){
				SetScrollPos(m_nScrollPos + m_nPageSize);	
			}
			else if (m_rcThumb.left > point.x){
				SetScrollPos(m_nScrollPos - m_nPageSize);
			}
		}
		Invalidate();
	}
}
void CComScrollBar::OnLButtonUp(UINT nFlags, CPoint point)
{
    KillTimer(TIMER_ALLOW);
	if (m_bClickBar)
	{
		m_bClickBar = FALSE;
		ReleaseCapture();
		Invalidate();
	}
	else if (m_bClickTrunk)
	{
		m_bClickTrunk = FALSE;
	}
	else if (m_bClickAllowUp)
	{
		m_bClickAllowUp = FALSE;
	}
	else if (m_bClickAllowDown)
	{
		m_bClickAllowDown = FALSE;
	}
}

BOOL CComScrollBar::Create( CWnd* pScrollCtrl, UINT nID, UINT nBarType /*= SB_VERT*/)
{
	BOOL	bRet;

	ASSERT(pScrollCtrl != NULL);

	m_pScrollCtrl = pScrollCtrl;
	m_pParent = pScrollCtrl->GetParent();
	m_nBarType = nBarType;

	bRet = CWnd::CreateEx(0, NULL, NULL, WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), m_pParent, nID);
	if (!bRet){
		return FALSE;
	}
	return TRUE;
}

void CComScrollBar::Layout()
{
	CRect rcClient, rect;

	if (!m_pParent->GetSafeHwnd()){
		return ;
	}

    if (!GetSafeHwnd()){
        return ;
    }

	m_pParent->GetClientRect(rcClient);
	rect = rcClient;
	if (m_nBarType == SB_VERT)
	{
		rect.DeflateRect(0, 1, 0,1);
		rect.left = rect.right - m_sizeScrollBar.cx;

		MoveWindow(rect);
		m_sizeScrollBar.cy = rect.Height();

		GetClientRect(rect);
		m_rcAllowUp = rect;

		m_rcAllowUp.bottom = m_rcAllowUp.top + CUIConfig::PagePrint_GetPrintTaskWndScrollSize();
        m_rcTopBorder=m_rcAllowUp;
        m_rcTopBorder.bottom =m_rcTopBorder.top +1;

		m_rcAllowDown = rect;
		m_rcAllowDown.top = m_rcAllowDown.bottom - CUIConfig::PagePrint_GetPrintTaskWndScrollSize();

        m_rcBottomBorder = m_rcAllowDown;
        m_rcBottomBorder.top = m_rcBottomBorder.bottom -1;
		m_rcTrunk = rect;
        m_rcTrunk.top = m_rcAllowUp.top;//+SIZE_SCROLL;//m_rcAllowUp.bottom;
        m_rcTrunk.bottom = m_rcAllowDown.bottom;//m_rcAllowDown.top;
	}
	else if (m_nBarType == SB_HORZ)
	{
		rect.DeflateRect(2, 0, 2, 8);
		rect.top = rect.bottom - m_sizeScrollBar.cx;
		MoveWindow(rect);
		m_sizeScrollBar.cy = rect.Width();

		GetClientRect(rect);
		m_rcAllowUp = rect;
        m_rcAllowUp.left += DIST_MID_SPACE;
		m_rcAllowUp.right = m_rcAllowUp.left + CUIConfig::PagePrint_GetPrintTaskWndScrollSize();

		m_rcAllowDown = rect;
		m_rcAllowDown.left = m_rcAllowDown.right - CUIConfig::PagePrint_GetPrintTaskWndScrollSize();

		m_rcTrunk = rect;
        m_rcTrunk.left = m_rcAllowUp.right;
        m_rcTrunk.right = m_rcAllowDown.left;
	}
}
BOOL CComScrollBar::SetBarSize( UINT nSize )
{
	m_sizeScrollBar.cx = nSize;
	return TRUE;
}

void CComScrollBar::_Draw( CDC* pDC )
{
	if (!pDC){
		return ;
	}
	CRect rect;
	CRCDC memDC;

	GetClientRect(rect);
	memDC.Init(pDC, rect.Width(), rect.Height());
    
	 if (m_pImgBk){
	RCG_FillImage(memDC.pDC, rect, m_pImgBk);
	}
	else{
        memDC.pDC->FillSolidRect(rect, RGB(135,206,235));
    }

	_DrawThunk(memDC.pDC);
	_DrawThumb(memDC.pDC);
	memDC.BitBlt();
}
void CComScrollBar::_DrawThunk( CDC *pDC )
{
	if (!pDC){
		return ;
	}
	RCG_DrawImageByGrid(pDC, m_rcTrunk, m_pThunk, 5);
}
void CComScrollBar::_DrawThumb( CDC *pDC )
{
	CRect	rect;
	Image*	pImage = NULL;
	int		nThumbHeight = 0;
	int		nThumbPos = 0;

	if (m_nAllSize <= m_nPageSize){
		return ;
	}

	nThumbHeight = (UINT)(m_nPageSize/(double)m_nAllSize * m_rcTrunk.Height());
    if (nThumbHeight < MIN_THUMB_LENGTH)
    {
        nThumbHeight = MIN_THUMB_LENGTH;
    }
	nThumbPos = (UINT)(m_nScrollPos/(double)m_nAllSize * m_rcTrunk.Height());
	if (nThumbPos <= 3){
		nThumbPos = 0;
	}
	else if(3 < nThumbPos && nThumbPos <= 6){
		nThumbPos = 6;
	}
	else if(nThumbPos+nThumbHeight >= m_rcTrunk.Height()-3){
		nThumbPos = m_rcTrunk.Height() - nThumbHeight;
	}
	else if((nThumbPos+nThumbHeight >= m_rcTrunk.Height()-6) && (nThumbPos+nThumbHeight < m_rcTrunk.Height()-3)){
		nThumbPos = m_rcTrunk.Height()-6 - nThumbHeight;
	}

	rect = m_rcTrunk;
	rect.bottom = rect.top + nThumbHeight;
	rect.OffsetRect(0, nThumbPos);

	m_rcThumb = rect;

    m_rcThumbHorzLine=m_rcThumb;
    m_rcThumbHorzLine.left += m_rcThumb.Width()/4;
    m_rcThumbHorzLine.right = m_rcThumbHorzLine.left + m_rcThumb.Width()/2;
    m_rcThumbHorzLine.top += m_rcThumb.Height()/2;
    m_rcThumbHorzLine.bottom =m_rcThumbHorzLine.top + 2;

    m_rcThumbBorder = m_rcThumb;
    m_rcThumbBorder.bottom = m_rcThumbBorder.top+1;

	if (m_nScrollPos <= 0)
	{
		if (m_bClickBar){
			pImage = m_thumbTop.pImgClick;
		}
		else if(m_bHoverBar){
			pImage = m_thumbTop.pImgHover;
		}
		else{
			pImage = m_thumbTop.pImgNormal;
		}
	}
	else if (m_nAllSize-m_nPageSize <= m_nScrollPos)
	{
		if (m_bClickBar){
			pImage = m_thumbBottom.pImgClick;
		}
		else if(m_bHoverBar){
			pImage = m_thumbBottom.pImgHover;
		}
		else{
			pImage = m_thumbBottom.pImgNormal;
		}
	}
	else
	{
		if (m_bClickBar){
			pImage = m_thumbCenter.pImgClick;
		}
		else if(m_bHoverBar){
			pImage = m_thumbCenter.pImgHover;
		}
		else{
			pImage = m_thumbCenter.pImgNormal;
		}
	}
	{
		RCG_DrawImageByGrid(pDC, m_rcThumb, pImage, 4);
	}
    _DrawThumbBorderAndLine(pDC);
}

void    CComScrollBar::_DrawThumbBorderAndLine(CDC* pDC)
{
    pDC->FillSolidRect(m_rcThumbHorzLine, RGB(204,198,198));
    m_rcThumbHorzLine.OffsetRect(0, -4);
    pDC->FillSolidRect(m_rcThumbHorzLine, RGB(204,198,198));
    m_rcThumbHorzLine.OffsetRect(0, 8);
    pDC->FillSolidRect(m_rcThumbHorzLine, RGB(204,198,198));
}

void CComScrollBar::_DrawAllow( CDC* pDC )
{
	if (!pDC){
		return;
	}

	if (m_nBarType == SB_VERT)
	{
		RCG_DrawImage(pDC, m_rcAllowUp, m_allowUp.pImgNormal);
		RCG_DrawImage(pDC, m_rcAllowDown, m_allowDown.pImgNormal);
		// up / left
		if (m_nScrollPos <= 0){
			RCG_DrawImage(pDC, m_rcAllowUp, m_allowUp.pImgDisable);
		}
		else if (m_bClickAllowUp){
			RCG_DrawImage(pDC, m_rcAllowUp, m_allowUp.pImgClick);
		}
		else if (m_bHoverAllowUp){
			RCG_DrawImage(pDC, m_rcAllowUp, m_allowUp.pImgHover);
		}

		//down / right
		if (m_nScrollPos >= m_nAllSize-m_nPageSize){
			RCG_DrawImage(pDC, m_rcAllowDown, m_allowDown.pImgDisable);
		}
		else if (m_bClickAllowDown){
			RCG_DrawImage(pDC, m_rcAllowDown, m_allowDown.pImgClick);
		}
		else if (m_bHoverAllowDown){
			RCG_DrawImage(pDC, m_rcAllowDown, m_allowDown.pImgHover);
		}
	}
	else
	{
		RCG_DrawImage(pDC, m_rcAllowUp, m_allowLeft.pImgNormal);
		RCG_DrawImage(pDC, m_rcAllowDown, m_allowRight.pImgNormal);
		// up / left
		if (m_nScrollPos <= 0){
			RCG_DrawImage(pDC, m_rcAllowUp, m_allowLeft.pImgDisable);
		}
		else if (m_bClickAllowUp){
			RCG_DrawImage(pDC, m_rcAllowUp, m_allowLeft.pImgClick);
		}
		else if (m_bHoverAllowUp){
			RCG_DrawImage(pDC, m_rcAllowUp, m_allowLeft.pImgHover);
		}

		//down / right
		if (m_nScrollPos >= m_nAllSize-m_nPageSize){
			RCG_DrawImage(pDC, m_rcAllowDown, m_allowRight.pImgDisable);
		}
		else if (m_bClickAllowDown){
			RCG_DrawImage(pDC, m_rcAllowDown, m_allowRight.pImgClick);
		}
		else if (m_bHoverAllowDown){
			RCG_DrawImage(pDC, m_rcAllowDown, m_allowRight.pImgHover);
		}
	}
}

BOOL CComScrollBar::InitSkin(CString szFolder)
{
	CString szNormal, szFile;

	USES_CONVERSION;
	#undef new
	if (szFolder.Right(1) != _T("\\")){
		szFolder += _T("\\");
	}

    szFile.Format(_T("%sVscroll_bk.png"), szFolder);
    if (PathFileExists(szFile)){
        m_pImgBk = RCG_NewImage((szFile));
    }

	szFile.Format(_T("%sVscroll_thunk.png"), szFolder);
	if (!PathFileExists(szFile)){
		return FALSE;
	}
	m_pThunk = RCG_NewImage((szFile));

	//thumb on center
	szNormal.Format(_T("%sVscroll_center_thumb_normal.png"), szFolder);
	if (!PathFileExists(szNormal)){
		return FALSE;
	}
	m_thumbCenter.pImgNormal = RCG_NewImage((szNormal));

	szFile.Format(_T("%sVscroll_center_thumb_hover.png"), szFolder);
	if (!PathFileExists(szFile)){
		szFile = szNormal;
	}
	m_thumbCenter.pImgHover = RCG_NewImage((szFile));

	szFile.Format(_T("%sVscroll_center_thumb_click.png"), szFolder);
	if (!PathFileExists(szFile)){
		szFile = szNormal;
	}
	m_thumbCenter.pImgClick = RCG_NewImage((szFile));

	//thumb on top
	szNormal.Format(_T("%sVscroll_top_thumb_normal.png"), szFolder);
	if (!PathFileExists(szNormal)){
		return FALSE;
	}
	m_thumbTop.pImgNormal = RCG_NewImage((szNormal));

	szFile.Format(_T("%sVscroll_top_thumb_hover.png"), szFolder);
	if (!PathFileExists(szFile)){
		szFile = szNormal;
	}
	m_thumbTop.pImgHover = RCG_NewImage((szFile));

	szFile.Format(_T("%sVscroll_top_thumb_click.png"), szFolder);
	if (!PathFileExists(szFile)){
		szFile = szNormal;
	}
	m_thumbTop.pImgClick = RCG_NewImage((szFile));

	//thumb on bottom
	szNormal.Format(_T("%s\\Vscroll_bottom_thumb_normal.png"), szFolder);
	if (!PathFileExists(szNormal)){
		return FALSE;
	}
	m_thumbBottom.pImgNormal = RCG_NewImage((szNormal));

	szFile.Format(_T("%sVscroll_bottom_thumb_hover.png"), szFolder);
	if (!PathFileExists(szFile)){
		szFile = szNormal;
	}
	m_thumbBottom.pImgHover = RCG_NewImage((szFile));

	szFile.Format(_T("%sVscroll_bottom_thumb_click.png"), szFolder);
	if (!PathFileExists(szFile)){
		szFile = szNormal;
	}
	m_thumbBottom.pImgClick = RCG_NewImage((szFile));

	//button
	//vert
	szNormal.Format(_T("%sbtn_up_normal.png"), szFolder);
	if (!PathFileExists(szNormal)){
		return FALSE;
	}
	m_allowUp.pImgNormal = RCG_NewImage((szNormal));

	szFile.Format(_T("%sbtn_up_hover.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowUp.pImgHover = RCG_NewImage((szFile));
	}
	else{
		m_allowUp.pImgHover = RCG_NewImage((szNormal));
	}

	szFile.Format(_T("%sbtn_up_click.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowUp.pImgClick = RCG_NewImage((szFile));
	}
	else{
		m_allowUp.pImgClick = RCG_NewImage((szNormal));
	}

	szFile.Format(_T("%sbtn_up_disable.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowUp.pImgDisable = RCG_NewImage((szFile));
	}
	else{
		m_allowUp.pImgDisable = RCG_NewImage((szNormal));
	}

	szNormal.Format(_T("%sbtn_down_normal.png"), szFolder);
	if (!PathFileExists(szNormal)){
		return FALSE;
	}
	m_allowDown.pImgNormal = RCG_NewImage((szNormal));

	szFile.Format(_T("%sbtn_down_hover.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowDown.pImgHover = RCG_NewImage((szFile));
	}
	else{
		m_allowDown.pImgHover = RCG_NewImage((szNormal));
	}

	szFile.Format(_T("%sbtn_down_click.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowDown.pImgClick = RCG_NewImage((szFile));
	}
	else{
		m_allowDown.pImgClick = RCG_NewImage((szNormal));
	}

	szFile.Format(_T("%sbtn_down_disable.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowDown.pImgDisable = RCG_NewImage((szFile));
	}
	else{
		m_allowDown.pImgDisable = RCG_NewImage((szNormal));
	}

	// horz
	szNormal.Format(_T("%sbtn_left_normal.png"), szFolder);
	if (!PathFileExists(szNormal)){
		return FALSE;
	}
	m_allowLeft.pImgNormal = RCG_NewImage((szNormal));

	szFile.Format(_T("%sbtn_left_hover.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowLeft.pImgHover = RCG_NewImage((szFile));
	}
	else{
		m_allowLeft.pImgHover = RCG_NewImage((szNormal));
	}

	szFile.Format(_T("%sbtn_left_click.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowLeft.pImgClick = RCG_NewImage((szFile));
	}
	else{
		m_allowLeft.pImgClick = RCG_NewImage((szNormal));
	}

	szFile.Format(_T("%sbtn_left_disable.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowLeft.pImgDisable = RCG_NewImage((szFile));
	}
	else{
		m_allowLeft.pImgDisable = RCG_NewImage((szNormal));
	}


	szNormal.Format(_T("%sbtn_right_normal.png"), szFolder);
	if (!PathFileExists(szNormal)){
		return FALSE;
	}
	m_allowRight.pImgNormal = RCG_NewImage((szNormal));

	szFile.Format(_T("%sbtn_right_hover.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowRight.pImgHover = RCG_NewImage((szFile));
	}
	else{
		m_allowRight.pImgHover = RCG_NewImage((szNormal));
	}

	szFile.Format(_T("%sbtn_right_click.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowRight.pImgClick = RCG_NewImage((szFile));
	}
	else{
		m_allowRight.pImgClick = RCG_NewImage((szNormal));
	}

	szFile.Format(_T("%sbtn_right_disable.png"), szFolder);
	if (PathFileExists(szFile)){
		m_allowRight.pImgDisable = RCG_NewImage((szFile));
	}
	else{
		m_allowRight.pImgDisable = RCG_NewImage((szNormal));
	}

	return TRUE;
}
void CComScrollBar::ReleaseSkin()
{
    RCG_DEL_POINT(m_pImgBk);
	RCG_DEL_POINT(m_pThunk);
	m_thumbTop.Release();
	m_thumbBottom.Release();
	m_thumbCenter.Release();
	m_allowDown.Release();
	m_allowLeft.Release();
	m_allowRight.Release();
	m_allowUp.Release();
}

void CComScrollBar::SetScrollPos( int pos, BOOL bInit/* = FALSE*/)
{
	int nLastPos = 0;

	if (bInit){
		if (m_nScrollPos != 0){
			m_nScrollPos = 0;
			Invalidate();
			return ;
		}
	}

	if (m_nAllSize <= m_nPageSize){
		return ;
	}
	if (pos == m_nScrollPos){
		return ;
	}
	if (m_nScrollPos <= 0 && pos <= 0){
		return ;
	}
	if (m_nScrollPos >= m_nAllSize-m_nPageSize && pos >= m_nScrollPos){
		return ;
	}

	nLastPos = m_nScrollPos;

	if (pos < 0){
		pos = 0;
	}
	else if(pos > m_nAllSize-m_nPageSize){
		pos = m_nAllSize-m_nPageSize;
	}
	m_nScrollPos = pos;
	m_pScrollCtrl->ScrollWindow(0, nLastPos - m_nScrollPos);

	Invalidate();
}
UINT CComScrollBar::GetScrollPos()
{
	return m_nScrollPos;
}
BOOL CComScrollBar::SetScrollInfo( SSCROLLINFO* si )
{
	if (!GetSafeHwnd())
	{
		return FALSE;
	}
	m_nAllSize = si->uiAllSize;
	m_nPageSize = si->uiPageSize;
	m_nOffsetSize = si->uiOffsetSize;
	Invalidate();
	return TRUE;
}
void CComScrollBar::GetScrollInfo( SSCROLLINFO* si )
{
	si->uiAllSize = m_nAllSize;
	si->uiPageSize = m_nPageSize;
	si->uiOffsetSize = m_nOffsetSize;
}

BOOL CComScrollBar::OnEraseBkgnd( CDC* pDC )
{
	return TRUE;
}






